package study.dq.jms.p2p;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author dongqun
 * @version 1.0
 * @description 类的功能描述
 * @date 2019/10/18 18:45
 */
public class TestCustomer {
    public static void main(String[] args){
        ExecutorService service = Executors.newFixedThreadPool(10);
        /*
        一下两种情况，第一种情况有五个线程同时运行，第二种情况只有一个线程在运行，其他四个都在等待，正好说明p2p方式只能有一个队列同时消费消息
         */
        //env1
//        Customer producter = new Customer("admin","admin","tcp://127.0.0.1:61616");
//        service.submit(new CustomerTask(producter));
//        service.submit(new CustomerTask(producter));
//        service.submit(new CustomerTask(producter));
//        service.submit(new CustomerTask(producter));
//        service.submit(new CustomerTask(producter));
        //env2
        service.submit(new CustomerTask(new Customer("admin","admin","tcp://127.0.0.1:61616")));
//        service.submit(new CustomerTask(new Customer("admin","admin","tcp://127.0.0.1:61616")));
//        service.submit(new CustomerTask(new Customer("admin","admin","tcp://127.0.0.1:61616")));
//        service.submit(new CustomerTask(new Customer("admin","admin","tcp://127.0.0.1:61616")));
//        service.submit(new CustomerTask(new Customer("admin","admin","tcp://127.0.0.1:61616")));
    }
    private static class CustomerTask implements Runnable{
        private Customer customer;
        public CustomerTask(Customer customer) {
            this.customer = customer;
        }
        @Override
        public void run() {
            while (true){
                try {
                    customer.getMessage("QUEUE_TEST_1");
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
